package com.runchinaup.smartbelt.receiver;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

/**
 * Created by liber on 2018/2/2.
 */

public class PhoneReceiver extends BroadcastReceiver {


    @Override
    public void onReceive(Context context, Intent intent) {

        System.out.println("action" + intent.getAction());
        if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)){
            //如果是去电（拨出）
            System.out.println("拨出");
        } else {
            //查了下android文档，貌似没有专门用于接收来电的action,所以，非去电即来电
            System.out.println("来电");
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
            //设置一个监听器
            tm.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_CALL_STATE);
        }



    }

}

